package com.sv.zgydor.controller;

import com.sv.zgydor.pojo.orcl.TCenunitTreeEntity;
import com.sv.zgydor.pojo.pg.TProjectListEntity;
import com.sv.zgydor.service.ProjectService;
import com.sv.zgydor.service.TCenunitTreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


@Controller
public class ProjectController {


    @Autowired
    private TCenunitTreeService tCenunitTreeService;

    @Autowired
    private ProjectService projectService;

    /**
     * 项目列表
     *
     * @return 返回项目列表页面
     */
    @RequestMapping(value = "/projectManagement", method = RequestMethod.GET)
    public ModelAndView index(int pid) {
        if (pid == 0) {
            TProjectListEntity project = new TProjectListEntity();
            return new ModelAndView("project/projectManagement", "project", project);
        }
        TProjectListEntity project = projectService.findProjectById(pid);
        return new ModelAndView("project/projectManagement", "project", project);

    }

    /**
     * 取得初始化的行政区划树（全国、省、直辖市）
     *
     * @return JSON结果集形式的行政区划树（全国、省、直辖市）
     */
    @RequestMapping(value = "/getRegionInitData", method = RequestMethod.GET)
    public @ResponseBody
    List<TCenunitTreeEntity> findInitData() {
        List<TCenunitTreeEntity> list = this.tCenunitTreeService.findInitData();
        return list;
    }

    /**
     * 按给定的行政区划CODE取得行政区划的子节点
     *
     * @param parCode 当前选择的行政区划
     * @return 当前选择的行政区划子节点
     */
    @RequestMapping(value = "/getRegionByParCode", method = RequestMethod.GET)
    public @ResponseBody
    List<TCenunitTreeEntity> findRegionByParCode(@RequestParam(value = "code") String parCode) {
        List<TCenunitTreeEntity> list = this.tCenunitTreeService.findRegionByParCode(parCode);
        return list;
    }

    /**
     * 取的所有项目
     *
     * @return
     */
    @RequestMapping(value = "/getAllProjects", method = RequestMethod.GET)
    public @ResponseBody
    List<TProjectListEntity> findAllProjects() {
        List<TProjectListEntity> list = this.projectService.findAllProjects();
        return list;
    }
}